home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Tool Chest / Development Tools & Languages / Dylan Related / Mindy / Mindy 1.2 - portable sources / compat / std-os.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-15  |  9.6 KB  |  420 lines  |  [TEXT/ttxt]

  1. /*
  2.  * std-os.h --
  3.  *
  4.  *    Provide emulation of standard unix where parts might be lacking.
  5.  *
  6.  *    This file is adapted from tcl-7.3 tclUnix.h and should be considered
  7.  *    a highly derivative workd covered by the following copyright.
  8.  *
  9.  *    Parts of this are irrelevant to mindy as it stands, but they're easier
  10.  *    to keep than to go back and dig them up later.
  11.  *
  12.  * tclUnix.h --
  13.  *
  14.  *    This file reads in UNIX-related header files and sets up
  15.  *    UNIX-related macros for Tcl's UNIX core.  It should be the
  16.  *    only file that contains #ifdefs to handle different flavors
  17.  *    of UNIX.  This file sets up the union of all UNIX-related
  18.  *    things needed by any of the Tcl core files.
  19.  *
  20.  *    Much of the material in this file was originally contributed
  21.  *    by Karl Lehenbauer, Mark Diekhans and Peter da Silva.
  22.  *
  23.  * Copyright (c) 1991-1993 The Regents of the University of California.
  24.  * All rights reserved.
  25.  *
  26.  * Permission is hereby granted, without written agreement and without
  27.  * license or royalty fees, to use, copy, modify, and distribute this
  28.  * software and its documentation for any purpose, provided that the
  29.  * above copyright notice and the following two paragraphs appear in
  30.  * all copies of this software.
  31.  * 
  32.  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  33.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  34.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  35.  * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36.  *
  37.  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  38.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  39.  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  40.  * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  41.  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  42.  *
  43.  * $Header: std-os.h,v 1.1 94/10/05 20:48:15 nkramer Exp $ SPRITE (Berkeley)
  44.  */
  45.  
  46. #ifndef _STD_OS_H_
  47. #define _STD_OS_H_    1
  48.  
  49. #include <errno.h>
  50. #include <fcntl.h>
  51. #include <pwd.h>
  52. #include <signal.h>
  53. #include <sys/param.h>
  54. #include <sys/types.h>
  55. #ifdef USE_DIRENT2_H
  56. #   include "std-dirent2.h"
  57. #else
  58. #   ifdef NO_DIRENT_H
  59. #    include "std-dirent.h"
  60. #   else
  61. #    include <dirent.h>
  62. #   endif
  63. #endif
  64. #include <sys/file.h>
  65. #include <sys/stat.h>
  66. #ifndef NO_SYS_TIME_H
  67. #    include <sys/time.h>
  68. #else
  69. #    include <time.h>
  70. #endif
  71. #ifndef NO_SYS_WAIT_H
  72. #   include <sys/wait.h>
  73. #endif
  74. #define pause    unistd_pause
  75. #ifndef NO_UNISTD_H
  76. #   include <unistd.h>
  77. #else
  78. #   include "std-unistd.h"
  79. #endif
  80. #undef pause
  81.  
  82. /*
  83.  * Not all systems declare the errno variable in errno.h. so this
  84.  * file does it explicitly.  The list of system error messages also
  85.  * isn't generally declared in a header file anywhere.
  86.  */
  87.  
  88. extern int errno;
  89.  
  90. /*
  91.  * The type of the status returned by wait varies from UNIX system
  92.  * to UNIX system.  The macro below defines it:
  93.  */
  94.  
  95. #ifdef AIX
  96. #   define WAIT_STATUS_TYPE pid_t
  97. #else
  98. #ifndef NO_UNION_WAIT
  99. #   define WAIT_STATUS_TYPE union wait
  100. #else
  101. #   define WAIT_STATUS_TYPE int
  102. #endif
  103. #endif
  104.  
  105. /*
  106.  * Supply definitions for macros to query wait status, if not already
  107.  * defined in header files above.
  108.  */
  109.  
  110. #ifndef WIFEXITED
  111. #   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
  112. #endif
  113.  
  114. #ifndef WEXITSTATUS
  115. #   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
  116. #endif
  117.  
  118. #ifndef WIFSIGNALED
  119. #   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
  120. #endif
  121.  
  122. #ifndef WTERMSIG
  123. #   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
  124. #endif
  125.  
  126. #ifndef WIFSTOPPED
  127. #   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
  128. #endif
  129.  
  130. #ifndef WSTOPSIG
  131. #   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
  132. #endif
  133.  
  134. /*
  135.  * Supply macros for seek offsets, if they're not already provided by
  136.  * an include file.
  137.  */
  138.  
  139. #ifndef SEEK_SET
  140. #   define SEEK_SET 0
  141. #endif
  142.  
  143. #ifndef SEEK_CUR
  144. #   define SEEK_CUR 1
  145. #endif
  146.  
  147. #ifndef SEEK_END
  148. #   define SEEK_END 2
  149. #endif
  150.  
  151. /*
  152.  * The stuff below is needed by the "time" command.  If this
  153.  * system has no gettimeofday call, then must use times and the
  154.  * CLK_TCK #define (from sys/param.h) to compute elapsed time.
  155.  * Unfortunately, some systems only have HZ and no CLK_TCK, and
  156.  * some might not even have HZ.
  157.  */
  158.  
  159. #ifdef NO_GETTOD
  160. #   include <sys/times.h>
  161. #   include <sys/param.h>
  162. #   ifndef CLK_TCK
  163. #       ifdef HZ
  164. #           define CLK_TCK HZ
  165. #       else
  166. #           define CLK_TCK 60
  167. #       endif
  168. #   endif
  169. #endif
  170.  
  171. /*
  172.  * Define access mode constants if they aren't already defined.
  173.  */
  174.  
  175. #ifndef F_OK
  176. #    define F_OK 00
  177. #endif
  178. #ifndef X_OK
  179. #    define X_OK 01
  180. #endif
  181. #ifndef W_OK
  182. #    define W_OK 02
  183. #endif
  184. #ifndef R_OK
  185. #    define R_OK 04
  186. #endif
  187.  
  188. /*
  189.  * On systems without symbolic links (i.e. S_IFLNK isn't defined)
  190.  * define "lstat" to use "stat" instead.
  191.  */
  192.  
  193. #ifndef S_IFLNK
  194. #   define lstat stat
  195. #endif
  196.  
  197. /*
  198.  * Define macros to query file type bits, if they're not already
  199.  * defined.
  200.  */
  201.  
  202. #ifndef S_ISREG
  203. #   ifdef S_IFREG
  204. #       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  205. #   else
  206. #       define S_ISREG(m) 0
  207. #   endif
  208. # endif
  209. #ifndef S_ISDIR
  210. #   ifdef S_IFDIR
  211. #       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  212. #   else
  213. #       define S_ISDIR(m) 0
  214. #   endif
  215. # endif
  216. #ifndef S_ISCHR
  217. #   ifdef S_IFCHR
  218. #       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  219. #   else
  220. #       define S_ISCHR(m) 0
  221. #   endif
  222. # endif
  223. #ifndef S_ISBLK
  224. #   ifdef S_IFBLK
  225. #       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  226. #   else
  227. #       define S_ISBLK(m) 0
  228. #   endif
  229. # endif
  230. #ifndef S_ISFIFO
  231. #   ifdef S_IFIFO
  232. #       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  233. #   else
  234. #       define S_ISFIFO(m) 0
  235. #   endif
  236. # endif
  237. #ifndef S_ISLNK
  238. #   ifdef S_IFLNK
  239. #       define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  240. #   else
  241. #       define S_ISLNK(m) 0
  242. #   endif
  243. # endif
  244. #ifndef S_ISSOCK
  245. #   ifdef S_IFSOCK
  246. #       define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  247. #   else
  248. #       define S_ISSOCK(m) 0
  249. #   endif
  250. # endif
  251.  
  252. /*
  253.  * Make sure that MAXPATHLEN is defined.
  254.  */
  255.  
  256. #ifndef MAXPATHLEN
  257. #   ifdef PATH_MAX
  258. #       define MAXPATHLEN PATH_MAX
  259. #   else
  260. #       define MAXPATHLEN 2048
  261. #   endif
  262. #endif
  263.  
  264. /*
  265.  * Make sure that L_tmpnam is defined.
  266.  */
  267.  
  268. #ifndef L_tmpnam
  269. #   define L_tmpnam 100
  270. #endif
  271.  
  272. /*
  273.  * Substitute our own versions for several system calls.  The
  274.  * versions retry automatically if interrupted by signals.
  275.  * (see protected.c).
  276.  *
  277.  * The only time a system call could be interrupted is if a
  278.  * signal_handler caught the signal and continued, so the
  279.  * fact that the system call got interrupted, too, is purely
  280.  * a nuisance rather than any kind of feature.
  281.  *
  282.  * I didn't enable the global definitions for mindy because
  283.  * interp/load.c already implements something similar.
  284.  */
  285.  
  286. #if 0
  287. #define open(a,b,c) protect_open(a,b,c)
  288. #define read(a,b,c) protect_read(a,b,c)
  289. #define waitpid(a,b,c) protect_waitpid(a,b,c)
  290. #define write(a,b,c) protect_write(a,b,c)
  291. #endif
  292.  
  293. EXTERN int    protect_open _ANSI_ARGS_((char *path, int oflag, int mode));
  294. EXTERN int    protect_read _ANSI_ARGS_((int fd, VOID *buf, size_t numBytes));
  295. EXTERN int    protect_waitpid _ANSI_ARGS_((pid_t pid, int *statPtr, int options));
  296. EXTERN int    protect_write _ANSI_ARGS_((int fd, VOID *buf, size_t numBytes));
  297.  
  298. /*
  299.  * Variables provided by the C library:
  300.  */
  301.  
  302. #if defined(_sgi) || defined(__sgi)
  303. #define environ _environ
  304. #endif
  305. extern char **environ;
  306.  
  307. /*
  308.  * Provide for minimal emulation of POSIX signals.
  309.  * Read the source for std-signal.h and sigaction.c
  310.  * before you start getting excited about using this.
  311.  */
  312. #ifdef NO_SIGACTION
  313. #include "std-signal.h"
  314. #endif
  315.  
  316. /*
  317.  * A series of tests to deal with unuseful select() definitions.
  318.  * Tk actually handles the mask bit twiddling itself, maintaining
  319.  * static arrays of fd_masks.
  320.  *
  321.  * Some systems have a useful sys/select.h.
  322.  */
  323. #ifdef HAVE_SYS_SELECT_H
  324. #include <sys/select.h>
  325. #endif
  326.  
  327. /*
  328.  * Define OPEN_MAX if it isn't already defined for this system.
  329.  */
  330.  
  331. #ifndef OPEN_MAX
  332. #   define OPEN_MAX 256
  333. #endif
  334.  
  335. /*
  336.  * The following macro defines the type of the mask arguments to
  337.  * select:
  338.  */
  339.  
  340. #ifndef NO_FD_SET
  341. #   define SELECT_MASK fd_set
  342. #else
  343. #   ifndef _AIX
  344.     typedef long fd_mask;
  345. #   endif
  346. #   if defined(_IBMR2)
  347. #    define SELECT_MASK void
  348. #   else
  349. #    define SELECT_MASK int
  350. #   endif
  351. #endif
  352.  
  353. /*
  354.  * Define "NBBY" (number of bits per byte) if it's not already defined.
  355.  */
  356.  
  357. #ifndef NBBY
  358. #   define NBBY 8
  359. #endif
  360.  
  361. /*
  362.  * The following macro defines the number of fd_masks in an fd_set:
  363.  */
  364.  
  365. #if !defined(howmany)
  366. #   define howmany(x, y) (((x)+((y)-1))/(y))
  367. #endif
  368. #ifdef NFDBITS
  369. #   define MASK_SIZE howmany(FD_SETSIZE, NFDBITS)
  370. #else
  371. #   define MASK_SIZE howmany(OPEN_MAX, NBBY*sizeof(fd_mask))
  372. #endif
  373.  
  374. /*
  375.  * Finally, provide a declaration for select.
  376.  */
  377.  
  378. #ifndef HAVE_SYS_SELECT_H
  379. #    ifndef SELECT_IN_TIME_H
  380.           extern int select _ANSI_ARGS_((int nfds, SELECT_MASK *readfds,
  381.                 SELECT_MASK *writefds, SELECT_MASK *exceptfds,
  382.                 struct timeval *timeout));
  383. #    endif
  384. #endif
  385.  
  386. /*
  387.  * Provide an error free implementation of fsync() or a simple
  388.  * declaration.
  389.  */
  390. #if NO_FSYNC
  391. #define fsync(fd)    0
  392. #else
  393. extern int fsync();
  394. #endif
  395.  
  396. /*
  397. ** Following are the remnants of system dependent stuff from
  398. ** mindy files.  What's left here was not covered by one of
  399. ** the earlier includes in std-c.h or this file.  My inclination
  400. ** is to simply write:
  401. **    extern int select(), fsync();
  402. ** and leave it at that.  For that matter, fsync() is a bit of
  403. ** overkill.
  404. */
  405.  
  406. #if defined(MACH) || defined(__osf__) || defined(ultrix)
  407. extern int select(int nfds, fd_set *readfds, fd_set *write_fds,
  408.           fd_set *except_fds, struct timeval *timeout);
  409. #endif
  410.  
  411. /* Was #if defined(__osf__) || defined(ultrix)
  412.  */
  413. #if defined(__osf__)
  414. extern int fsync(int filedes);
  415. #include <exc_handling.h>
  416. #endif
  417.  
  418.  
  419. #endif    /* _STD_OS_H_ */
  420.